local paiyi = fk.CreateSkill {
    name = "gai__paiyi",
  }
  
  Fk:loadTranslationTable{
    ["gai__paiyi"] = "排异",
    [":gai__paiyi"] = "出牌阶段各限一次，你可移去一张“权”并选择一项：1.令一名角色摸X张牌；2.对至多X名角色各造成1点伤害（X为“权”数且至少为1）。",

    ["#gai__paiyi_draw"] = "排异：移去一张“权”，令一名角色摸%arg张牌",
    ["#gai__paiyi_damage"] = "排异：移去一张“权”，对至多%arg名角色造成伤害",
  
    ["$gai__paiyi1"] = "坏吾大计者，罪死不赦！",
    ["$gai__paiyi2"] = "攻讦此子，祸咎已除！",
  }
  
  paiyi:addEffect("active", {
    anim_type = "offensive",
    expand_pile = "gai__zhonghui_power",
    prompt = function(self, player, selected_cards, selected_targets)
      local n = math.max(#player:getPile("gai__zhonghui_power") - 1, 1)
      if self.interaction.data == "draw_card" then
        return "#gai__paiyi_draw:::"..n
      else
        return "#gai__paiyi_damage:::"..n
      end
    end,
    card_num = 1,
    min_target_num = 1,
    max_target_num = function(self, player)
      if self.interaction.data == "draw_card" then
        return 1
      else
        return math.max(#player:getPile("gai__zhonghui_power") - 1, 1)
      end
    end,
    interaction = function(self, player)
      local choices = {}
      if player:getMark("gai__paiyi_draw-phase") == 0 then
        table.insert(choices, "draw_card")
      end
      if player:getMark("gai__paiyi_damage-phase") == 0 then
        table.insert(choices, "Damage")
      end
      return UI.ComboBox { choices = choices, all_choices = {"draw_card", "Damage"} }
    end,
    can_use = function(self, player)
      return #player:getPile("gai__zhonghui_power") > 0 and
        (player:getMark("gai__paiyi_draw-phase") == 0 or player:getMark("gai__paiyi_damage-phase") == 0)
    end,
    card_filter = function(self, player, to_select, selected)
      return #selected == 0 and table.contains(player:getPile("gai__zhonghui_power"), to_select)
    end,
    target_filter = function(self, player, to_select, selected)
      if self.interaction.data == "draw_card" then
        return #selected == 0
      else
        return #selected < math.max(#player:getPile("gai__zhonghui_power") - 1, 1)
      end
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      room:moveCards({
        from = player,
        ids = effect.cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = paiyi.name,
      })
      if player.dead then return end
      if self.interaction.data == "draw_card" then
        room:setPlayerMark(player, "gai__paiyi_draw-phase", 1)
        local target = effect.tos[1]
        if not target.dead then
          target:drawCards(math.max(#player:getPile("gai__zhonghui_power"), 1), paiyi.name)
        end
      else
        room:setPlayerMark(player, "gai__paiyi_damage-phase", 1)
        local tos = table.simpleClone(effect.tos)
        room:sortByAction(tos)
        for _, p in ipairs(tos) do
          if not p.dead then
            room:damage{
              from = player,
              to = p,
              damage = 1,
              skillName = paiyi.name,
            }
          end
        end
      end
    end,
  })
  
  return paiyi